package com.situ.yB2C.util;

import javax.servlet.http.HttpSession;

import com.situ.yB2C.user.pojo.User;

public class ContextUtil {
	public static final String SESSION_LOGIN_BUYER = "login_buyer";
	public static final String SESSION_CART_NAME="yB2C_cart";//放置在session中的购物车的名称
	//写出到浏览器的Cookie的name, 先自己造个域名
	public static final String COOKIE_BUYER = "www.yB2C.buyer.com";
	public static final String SEPERTOR = "~#~";
	public static final String DEFAULT_ADMIN_CODE="admin";//超级管理员
	public static final String DEFAULT_ADMIN_PASS="123456";
	public static final String SESSION_LOGIN_ADMIN = "login_admin";
	/*
	 * public static final String DEFAULT_ADMIN_CODE = "admin"; public static final
	 * String DEFAULT_ADMIN_PASS = "123"; public static final String
	 * SESSION_LOGIN_ADMIN = "login_admin";
	 */
	
	
	//定义一个静态的realPath 准备接受ServletContextListener得到realPath
	//public static  String realPath ;
	//将项目的文件写出到外面 定义的项目的文件路径
	public static  String realPath ="D:/webfiles/yB2C/" ;
	
	/**
	 * #得到商家的登录账号
	 * @param session
	 * @return
	 */
	public static String  getAdminUserCode(HttpSession session) {
		Object object =session.getAttribute(SESSION_LOGIN_ADMIN);
		if (object !=null) {
			return ((User)object).getUserCode();
		}
		return null;
	}
	/**
	 * #得到买家的登陆账号
	 * @param session
	 * @return
	 */
	public static String  getBuyerUserCode(HttpSession session) {
		Object object =session.getAttribute(SESSION_LOGIN_BUYER);
		if (object !=null) {
			return ((User)object).getUserCode();
		}
		return null;
	}
	/**
	 * #得到登录的买家的Id
	 * @param session
	 * @return
	 */
	public static Long getBuyerUserId(HttpSession session) {
		Object object =session.getAttribute(SESSION_LOGIN_BUYER);
		if (object !=null) {
			return ((User)object).getRowId();
		}
		return null;
	}
	
}
